import Vue from "vue";
import Vuex from "vuex";
import {Loading} from "element-ui";

Vue.use(Vuex);

const modulesFiles = require.context("./modules", true, /\.js$/);

const modules = modulesFiles.keys().reduce((modules, modulePath) => {
  // set './app.js' => 'app'
  const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, "$1");
  const value = modulesFiles(modulePath);
  modules[moduleName] = value.default;
  return modules;
}, {});

const store = new Vuex.Store({
  mutations: {
    GET_VUEX: (state, vuex) => {
      state.file = vuex;
    },
    showLoading(state,val)
    {
      let loadingInstance = Loading.service(state.options);
      val? Loading.service(state.options) : loadingInstance.close()
    }
  },
  state:{
    options:{
      lock: true,
      text: '正在拼命计算中...',//加载动画的文字
      spinner:'el-icon-loading',//加载动画的图标
      background:'rgba(0,0,0,0.8)'//加载动画的背景
    },
  },
  modules
});

export default store;
